<style>
    /*样式写这里*/
    .demo-table table tbody tr td span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 580px;
        display: block;
    }

    .conter_box {
        display: none;
    }

    .conter_box.active {
        display: block;
    }

    .config_file .CodeMirror {
        height: 400px;
    }

    .config_user_file .CodeMirror {
        height: 360px;
    }

    .logs_code_style {
        margin: 0px;
        background-color: #333;
        color: #fff;
        padding: 0 5px;
        width: 100%;
        height: 520px;
        line-height: 20px;
    }

    .select_list {
        width: 190px;
        height: 35px;
        line-height: 35px;
        border: 1px solid #888;
        border-radius: 2px;
        display: inline-block;
        cursor: pointer;
        position: relative;
        margin-left: 15px;

        background: #fff url() no-repeat right center;
    }

    .select_list .select_item {
        width: 100%;
        display: block;
        /* text-align: center; */
        padding-left: 10px;
    }

    .select_list .select {
        width: 190px;
        position: absolute;
        left: -1px;
        top: 33px;
        border: 1px solid #999;
        background: #fff;
        max-height: 250px;
        overflow: auto;
    }

    .select_list .select li {
        height: 35px;
        line-height: 35px;
        padding: 0 10px;
    }

    .select_list .select li.active {
        background: #e6e6e6;
    }

    .select_list .select li:hover {
        background: #e6e6e6;
    }

    .install_version_box .btn-danger {
        color: #fff;
        background-color: #d9534f;
        border-color: #d43f3a;
    }

    .install_version_box {
        padding: 15px 25px;
    }

    .tomcat_log {
        margin: 0px;
        width: 100%;
        height: 370px;
        background-color: #424251;
        overflow: auto;
        line-height: 22px;
        color: #fff;
        padding-left: 10px;
        font-family: arial;
        margin-top: 10px;
        outline: none;
    }

    .database_property .line .tname {
        width: 180px;
    }

    .database_property .line {
        padding: 3px 0;
    }

    .database_property .line .info-r {
        margin-bottom: 2px;
    }

    .box_table_conter {
        height: 450px;
        overflow: auto;
    }

    .bt_conter .line {
        padding: 0px;
    }
</style>
<div class="bt-form">
    <div class="bt-w-main">
        <!--菜单部分-->
        <div class="bt-w-menu">
            <p class="bgw">服务状态</p>
            <p>数据库列表</p>
            <p>版本管理</p>
            <!-- <p >安装卸载pgsql</p> -->
            <p>配置修改</p>
            <p>客户端认证</p>
            <!-- <p onclick="demo.get_clint_config()">客户端认证配置修改</p> -->
            <p>存储位置</p>
            <p>端口</p>
            <p>当前状态</p>
            <p>性能调整</p>
            <p>日志</p>
            <p>慢日志</p>
        </div>
        <!--内容部分-->
        <div class="bt-w-con pd15">
            <div class="plugin_body">
                <!-- 服务视图 -->
                <div class="conter_box active service_view">
                    <div class="soft-man-con bt-form">
                        <p class="status">当前状态：
                            <span>开启</span>
                            <span style="color: #20a53a; margin-left: 3px;" class="glyphicon glyphicon glyphicon-play"></span>
                        </p>
                        <div class="sfm-opt">
                            <button class="btn btn-default btn-sm btn_server_start" style="display: none" onclick="bt.pub.set_server_status('pgsql','start')">启动</button>
                            <button class="btn btn-default btn-sm btn_server_stop" onclick="bt.pub.set_server_status('pgsql','stop')">停止</button>
                            <button class="btn btn-default btn-sm" onclick="bt.pub.set_server_status('pgsql','restart')">重启</button>
                            <button class="btn btn-default btn-sm" onclick="bt.pub.set_server_status('pgsql','reload')">重载配置</button>
                        </div>
                    </div>
                </div>
                <!-- 数据库列表 -->
                <div class="conter_box database_list">
                    <button class="btn btn-success btn-sm va0 mb15 add_database">添加数据库</button>
                    <div class="box_table_conter divtable">
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <th>数据库名</th>
                                <th>用户名</th>
                                <th>密码</th>
                                <th>备份</th>
                                <th style="text-align: right;">操作</th>
                            </tr>
                            </thead>
                            <tbody class="database_table"></tbody>
                        </table>
                    </div>
                </div>
                <!-- 版本管理 -->
                <div class="conter_box install_version_box">
                    <span>PgSQL版本:</span>
                    <div class="select_list"><span class="select_item">pgsql <i style="font-style: normal;">&nbsp;&nbsp;[ 获取中 ]&nbsp;&nbsp;</i></span>
                        <ul class="select" style="display:none;">
                        </ul>
                    </div>
                    <button class="btn btn-success btn-sm va0 ml5 install_pgsql">安装版本</button>
                    <button class="btn btn-danger btn-sm va0 ml5 uninstall_pgsql" style="display: none;">卸载版本</button>
                    <textarea class="install_log tomcat_log" style="display:none"></textarea>
                    <ul class="help-info-text c7">
                        <li style="color:red">安装PgSQL版本可能会耗时比较久请耐心等候</li>
                        <li style="color:red">切换版本，请先卸载当前版本，同时手动备份当前数据库文件。</li>
                    </ul>
                </div>
                <!-- 配置文件 -->
                <div class="conter_box config_file">
                    <div class="soft-man-con bt-form">
                        <p style="color: #666; margin-bottom: 7px">提示：Ctrl+F 搜索关键字，Ctrl+G 查找下一个，Ctrl+S 保存，Ctrl+Shift+R 查找替换!</p>
                        <textarea class="bt-input-text" style="height: 320px; line-height: 18px; display: none;" id="config_file"></textarea>
                        <button class="btn btn-success btn-sm save_config_file" style="margin-top:10px;">保存</button>
                        <button class="btn btn-success btn-sm " style="margin-top:10px;" onclick="bt.pub.set_server_status('pgsql','restart')">重启数据库</button>
                        <ul class="help-info-text c7">
                            <li>此处为pgsql主配置文件,若您不了解配置规则,请勿随意修改。</li>
                        </ul>
                    </div>
                </div>
                <!-- 安全配置文件 -->
                <div class="conter_box config_user_file">
                    <div class="soft-man-con bt-form">
                        <p style="color: #666; margin-bottom: 7px">提示：Ctrl+F 搜索关键字，Ctrl+G 查找下一个，Ctrl+S 保存，Ctrl+Shift+R 查找替换!</p>
                        <textarea class="bt-input-text" style="height: 320px; line-height: 18px; display: none;" id="config_user_file"></textarea>
                        <button class="btn btn-success btn-sm save_config_user_file" style="margin-top:10px;">保存</button>
                        <ul class="help-info-text c7">
                            <li style="color:red;">此配置文件可以配置允许哪些用户连接到哪个数据库，允许哪些IP或者哪个网段的IP连接到本服务器，以及指定连接时使用的身份验证模式!</li>
                            <li>此处为pgsql客户端认证配置文件,若您不了解配置规则,请勿随意修改。</li>
                        </ul>
                    </div>
                </div>


                <div class="conter_box database_dir">
                    <div class="info-r  ml0">
                        <input name="datadir" class="bt-input-text mr5" id="database_dir_val" type="text" style="width:330px" value="">
                        <span class="glyphicon cursor mr5 glyphicon-folder-open" onclick="ChangePath('database_dir_val')"></span>
                        <button name="btn_change_path" class="btn btn-success btn-sm mr5 ml5 btn_change_path">迁移</button>
                    </div>
                </div>
                <div class="conter_box database_port">
                    <div class="info-r  ml0">
                        <input name="port" class="bt-input-text mr5 port" id="database_port_val" type="number" min="1" max="65534" style="width:100px" value="">
                        <button name="btn_change_port" class="btn btn-success btn-sm mr5 ml5 btn_change_port">修改</button>
                    </div>
                </div>
                <div class="conter_box database_status">
                    <table id="tab-pgsql-status" class="table table-hover table-bordered" style="margin-bottom: 10px;">
                        <tbody></tbody>
                    </table>
                </div>
                <div class="conter_box database_property">
                    <div class="bt-form"></div>
                    <div class="line ">
                        <div class="info-r  ml0">
                            <button class="btn btn-success btn-sm mr5 ml5" onclick="bt.pub.set_server_status('pgsql','restart')" style="margin-left: 605px;margin-top: 55px;">重启数据库</button>
                            <button class="btn btn-success btn-sm mr5 ml5 save_pgsql_property">保存</button>
                        </div>
                    </div>
                </div>
                <div class="conter_box database_logs">
                    <textarea id="database_logs_val" class="logs_code_style"></textarea>
                </div>
                <div class="conter_box database_slow_logs">
                    <textarea id="database_slow_logs_val" class="logs_code_style"></textarea>
                </div>
            </div>
        </div>
    </div>
</div>


<!--JS脚本部分，不要将JS脚本写在其它地方-->
<script type="text/javascript" src="/static/js/clipboard.min.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
    var pgsql = {
        plugin_name: 'pgsql_manager',
        config_code: {},
        config_user_code: {},
        pgsql_version: true,
        init: function () {
            var _this = this;

            //左测菜单切换效果
            $('.layui-layer-page').width('900px');

            this.total_version_req({get_pgsql_version: 1, get_pgsql_install_info: 1, tips: '获取PgSQL服务中，请稍后...'}, function (res) {
                var rdata = res.data;
                _this.pgsql_version = true;//已安装
                if (rdata.pgsql_version == '') {
                    _this.pgsql_version = false;//未安装
                    _this.get_pgsql_install_status();
                    _this.create_version_view();
                    $(".bt-w-menu p").eq(2).addClass('bgw').siblings().removeClass('bgw');
                    $('.conter_box').eq(2).show().siblings().hide();
                }
            });
            $(".bt-w-menu p").click(function () {
                var index = $(this).index();
                if (!_this.pgsql_version) {
                    layer.msg('请选择安装的数据库版本', {icon: 0});
                    return false;
                }
                $(this).addClass('bgw').siblings().removeClass('bgw');
                $('.conter_box').eq(index).show().siblings().hide();
                switch (index) {
                    case 0:
                        _this.create_service_view();
                        break;
                    case 1:
                        _this.create_database_view();
                        break;
                    case 2:
                        _this.create_version_view();
                        break;
                    case 3:
                        //if ($("#config_file").val() == "")
                        _this.create_config_view();
                        break;
                    case 4:
                        //if ($("#config_user_file").val() == "")
                            _this.create_user_config_view();
                        break;
                    case 5:
                        //if ($("#database_dir_val").val() == "")
                            _this.create_dir_view();
                        break;
                    case 6:
                        //if ($("#database_port_val").val() == "")
                            _this.create_port_view();
                        break;
                    case 7:
                        //if ($("#tab-pgsql-status tbody").html() == "")
                            _this.create_status_view();
                        break;
                    case 8:
                        _this.create_property_view();
                        break;
                    case 9:
                        _this.create_logs_view();
                        break;
                    case 10:
                        _this.create_slow_logs_view();
                        break;
                }
            });

            // 添加数据库(OK)
            $('.add_database').click(function () {
                layer.open({
                    type: 1,
                    closeBtn: 2,
                    title: '添加数据库',
                    area: '450px', //宽高
                    btn: ['确定', '取消'],
                    content: '<div class="bt_conter bt-form pd15" style="height:auto;width:100%;">\
                            <div class="line"><span class="tname">数据库名</span>\
                                <div class="info-r c4"><input class="bt-input-text" type="text" name="database_name" placeholder="请输入数据库名称" autocomplete="off" value="" style="width:270px"></div>\
                            </div>\
                            <div class="line"><span class="tname">用户名</span>\
                                <div class="info-r c4"><input class="bt-input-text" type="text" name="user_name" placeholder="请输入数据库用户名" autocomplete="off" value="" style="width:270px"></div>\
                            </div>\
                            <div class="line"><span class="tname">密码</span>\
                                <div class="info-r c4">\
                                    <input class="bt-input-text" type="text" name="user_paw" placeholder="请输入数据库密码" autocomplete="off" value="" style="width:270px">\
                                    <span class="glyphicon cursor mr5 glyphicon-repeat" id="repeat_paw" style="margin-left:5px;"></span>\
                                </div>\
                            </div>\
                            <div class="line">\
                                <span class="tname">访问权限</span>\
                                <div class="info-r c4">\
                                    <select name="listen_ip"  class="bt-input-text mr5" style="width:100px">\
                                        <option value="127.0.0.1/32">本地服务器</option>\
                                        <option value="0.0.0.0/0">所有人</option>\
                                        <option value="ip">指定网段</option>\
                                    </select>\
                                    <input class="bt-input-text mr5" type="text" name="ip_segment" placeholder="如: 192.168.1.0/24" style="width: 162px;display:none;">\
                                </div>\
                            </div>\
                        </div>',
                    success: function (layero, index) {
                        $('[name="user_paw"]').val(bt.get_random(12))
                        $('#repeat_paw').click(function () {
                            $('[name="user_paw"]').val(bt.get_random(12));
                        });
                        $('[name="listen_ip"]').change(function () {
                            if ($(this).val() == 'ip') {
                                $('[name="ip_segment"]').show();
                            } else {
                                $('[name="ip_segment"]').hide();
                            }
                        });
                    },
                    yes: function (index, layero) {
                        var database_name = $('[name="database_name"]').val(),
                            user_name = $('[name="user_name"]').val(),
                            user_paw = $('[name="user_paw"]').val(),
                            listen_ip = $('[name="listen_ip"]').val(),
                            ip_segment = $('[name="ip_segment"]').val(),
                            regEn = /[`~!@#$%^&*()_+<>?:"{},.\\/;'[\]]/im,
                            regCn = /[·！#￥（——）：；“”‘、，|《。》？、【】[\]]/im;
                        if (regEn.test(database_name) || regCn.test(database_name)) {
                            layer.msg('数据库名称不能包含特殊字符', {icon: 2});
                            return false;
                        }
                        if (database_name == '') {
                            layer.msg('请输入数据库名称', {icon: 2});
                            return false;
                        }
                        if (user_name == '') {
                            layer.msg('请输入数据库用户名', {icon: 2});
                            return false;
                        }
                        if (user_paw == '') {
                            layer.msg('请输入数据库密码', {icon: 2});
                            return false;
                        }
                        if ($('[name="listen_ip"]').val() == 'ip') listen_ip = ip_segment;
                        _this.add_database_req({
                            username: user_name,
                            password: user_paw,
                            database: database_name,
                            listen_ip: listen_ip
                        }, function (res) {
                            layer.msg(res.data, {icon: res.status == 'sucess' ? 1 : 2});
                            if (res.status) {
                                layer.close(index)
                                _this.create_database_view(function () {
                                    layer.msg(res.data, {icon: 1});
                                })
                            }
                        });
                    }
                });
            });

            // 设置密码显示(OK)
            $('.database_table').on('click', '.set_paw_ico', function () {
                var paw = $(this).prev().attr('data-paw')
                if ($(this).hasClass('glyphicon-eye-open')) {
                    $(this).addClass('glyphicon-eye-close').removeClass('glyphicon-eye-open').prev().html(paw);
                } else {
                    $(this).addClass('glyphicon-eye-open').removeClass('glyphicon-eye-close').prev().html('******');
                }
            });

            // 设置密码复制(OK)
            var clipboard = new ClipboardJS('.database_table .copy_paw');
            clipboard.on('success', function (e) {
                layer.msg('复制成功!', {icon: 1});
                e.clearSelection();
            });
            clipboard.on('error', function (e) {
                layer.msg('复制失败，请手动Ctrl+C复制。', {icon: 2});
            });

            // 备份列表(OK)
            $('.database_table').on('click', '.backups_list', function () {
                var database = $(this).attr('data-database');
                layer.open({
                    type: 1,
                    closeBtn: 2,
                    title: '数据库【' + database + '】备份列表',
                    area: '650px', //宽高
                    content: '<div class="divtable pd15">\
                        <button  class="btn btn-success btn-sm btn_data_backup" type="button" style="margin-bottom:10px">备份</button>\
                        <table class="table table-hover">\
                            <thead>\
                                <tr><th>文件名称</th><th>文件大小</th><th>备份时间</th><th style="text-align: right;">操作</th></tr>\
                            </thead>\
                            <tbody class="backups_table"></tbody>\
                        </table>\
                    </div>',
                    success: function (layero, index) {
                        // 添加备份文件
                        $('.btn_data_backup').click(function () {
                            var filename = $(this).attr('data-filename');
                            _this.add_backups_req({database: database}, function (res) {
                                _this.create_backups_list({database, database}, function () {
                                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                                });
                            });
                        });

                        // 导入备份文件
                        $('.backups_table').on('click', '.import_backups', function () {
                            var filename = $(this).attr('data-filename');
                            var confirm = layer.confirm('是否恢复&nbsp;[' + filename + ']&nbsp;备份文件？', {title: '提示', btn: ['确定', '取消'], icon: 0, closeBtn: 2}, function () {
                                _this.recover_backups_req({filename: filename}, function (res) {
                                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                                });
                            });
                        });

                        // 下载备份文件
                        $('.backups_table').on('click', '.download_backups', function () {
                            var loadT = layer.msg('正在下载备份文件，请稍后...', {icon: 16, time: 0, shade: 0.3});
                            setTimeout(function () {
                                layer.close(loadT)
                            }, 1000);
                        });

                        // 删除备份文件
                        $('.backups_table').on('click', '.del_backups', function () {
                            var filename = $(this).attr('data-filename');
                            var confirm = layer.confirm('是否删除&nbsp;[' + filename + ']&nbsp;备份文件？', {title: '提示', btn: ['确定', '取消'], icon: 0, closeBtn: 2}, function () {
                                _this.del_backups_req({filename: filename}, function (res) {
                                    _this.create_backups_list({database, database}, function () {
                                        layer.msg(res.data, {icon: res.status ? 1 : 2});
                                    });
                                });
                            });
                        });
                    }
                });
                _this.create_backups_list({database: database});
            });

            // 导入数据库
            $('.database_table').on('click', '.import_backups', function () {
                var database = $(this).attr('data-database');
                layer.open({
                    type: 1,
                    closeBtn: 2,
                    title: '数据库【' + database + '】，本地文件导入备份',
                    area: '650px', //宽高
                    content: '<div class="divtable pd15">\
                                <button  class="btn btn-success btn-sm import_file_database" type="button" style="margin-bottom:10px" onclick="pgsql.upload_files()">从本地上传</button>\
                                <table class="table table-hover">\
                                    <thead>\
                                        <tr><th>文件名称</th><th>文件大小</th><th>上传时间</th><th style="text-align: right;">操作</th></tr>\
                                    </thead>\
                                    <tbody class="import_file_table"></tbody>\
                                </table>\
                            </div>',
                    success: function () {
                        // 恢复备份文件
                        $('.import_file_table').on('click', '.import_backups', function () {
                            var filename = $(this).attr('data-filename');
                            var filepath = $(this).attr('data-filepath');
                            var confirm = layer.confirm('是否恢复&nbsp;[' + filename + ']&nbsp;备份文件？', {title: '提示', btn: ['确定', '取消'], icon: 0, closeBtn: 2}, function () {
                                _this.recover_import_req({filepath: filepath, database: database}, function (res) {
                                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                                });
                            });
                        });
                        // 删除导入文件
                        $('.import_file_table').on('click', '.del_backups', function () {
                            var filename = $(this).attr('data-filename');
                            var confirm = layer.confirm('是否删除&nbsp;[' + filename + ']&nbsp;导入文件？', {title: '提示', btn: ['确定', '取消'], icon: 0, closeBtn: 2}, function () {
                                _this.del_import_req({filename: filename, database: database}, function (res) {
                                    _this.create_import_view(function () {
                                        layer.msg(res.data, {icon: res.status ? 1 : 2});
                                    })
                                });
                            });
                        });
                    }
                });
                _this.create_import_view()
            });

            // 权限管理(OK)
            $('.database_table').on('click', '.authority_manage', function () {
                var database = $(this).attr('data-database'), username = $(this).attr('data-username'), listen_ip = $(this).attr('data-listenIp')
                layer.open({
                    type: 1,
                    closeBtn: 2,
                    title: '权限管理【' + database + '】',
                    area: '420px', //宽高
                    btn: ['确定', '取消'],
                    content: '<div class="bt_conter bt-form pd15" style="height:auto;width:100%;">\
                        <div class="line">\
                            <span class="tname">访问权限</span>\
                            <div class="info-r c4">\
                                <select name="listen_ip"  class="bt-input-text mr5" style="width:100px">\
                                    <option value="127.0.0.1/32" ' + (listen_ip == '127.0.0.1/32' ? 'selected="selected"' : '') + '>本地服务器</option>\
                                    <option value="0.0.0.0/0" ' + (listen_ip == '0.0.0.0/0' ? 'selected="selected"' : '') + '>所有人</option>\
                                    <option value="ip" ' + (listen_ip != '0.0.0.0/0' && listen_ip != '127.0.0.1/32' ? 'selected="selected"' : '') + '>指定网段</option>\
                                </select>\
                                <input class="bt-input-text mr5" type="text" name="ip_segment" placeholder="如: 192.168.1.0/24" style="width: 150px;' + (listen_ip != '0.0.0.0/0' && listen_ip != '127.0.0.1/32' ? ('" value="' + listen_ip + '"') : 'display:none;') + '">\
                            </div>\
                        </div>\
                    </div>',
                    success: function (layero, index) {
                        $('[name="listen_ip"]').change(function () {
                            if ($(this).val() == 'ip') {
                                $('[name="ip_segment"]').show();
                            } else {
                                $('[name="ip_segment"]').hide();
                            }
                        });
                    },
                    yes: function (index, layero) {
                        var listen_ip = '';
                        if ($('[name="listen_ip"]').val() == 'ip') {
                            listen_ip = $('[name="ip_segment"]').val();
                        } else {
                            listen_ip = $('[name="listen_ip"]').val();
                        }
                        _this.set_authority_req({
                            username: username,
                            listen_ip: listen_ip
                        }, function (res) {
                            layer.msg(res.data, {icon: res.status ? 1 : 2});
                            if (res.status == 1) {
                                layer.close(index);
                            }
                        });
                    }
                });
            });

            // 修改密码(OK)
            $('.database_table').on('click', '.change_password', function () {
                var database = $(this).attr('data-database'), username = $(this).attr('data-username'), password = $(this).attr('data-password');
                layer.open({
                    type: 1,
                    closeBtn: 2,
                    title: '修改密码【' + database + '】',
                    area: '450px', //宽高
                    btn: ['确定', '取消'],
                    content: '<div class="bt_conter bt-form pd15" style="height:auto;width:100%;">\
                        <div class="line"><span class="tname">用户名</span>\
                            <div class="info-r c4"><input class="bt-input-text" type="text" name="user_name" placeholder="请输入数据库用户名" autocomplete="off" value="' + username + '" disabled="disabled" style="width:260px"></div>\
                        </div>\
                        <div class="line"><span class="tname">密码</span>\
                            <div class="info-r c4">\
                                <input class="bt-input-text" type="text" name="user_paw" placeholder="请输入数据库密码" autocomplete="off" value="' + password + '" style="width:260px">\
                                <span class="glyphicon cursor mr5 glyphicon-repeat" id="repeat_paw" style="margin-left:5px;"></span>\
                            </div>\
                        </div>\
                    </div>',
                    success: function (layero, index) {
                        $('#repeat_paw').click(function () {
                            $('[name="user_paw"]').val(bt.get_random(12));
                        });
                    },
                    yes: function (index, layero) {
                        var username = $('[name="user_name"]').val(), password = $('[name="user_paw"]').val();
                        _this.set_password_req({
                            username: username,
                            password: password
                        }, function (res) {
                            layer.msg(res.data, {icon: res.status ? 1 : 2});
                            if (res.status == 1) {
                                layer.close(index);
                                _this.create_database_view(function () {
                                    layer.msg(res.data, {icon: 1});
                                });
                            }
                        });
                    }
                });
            });

            // 删除数据库
            $('.database_table').on('click', '.del_database', function () {
                var database = $(this).attr('data-database');
                // var confirm = layer.confirm('是否删除&nbsp;['+ database  +']&nbsp;数据库？', {title:'提示',btn: ['确定','取消'],icon:0,closeBtn:2}, function(){
                var confirm = layer.open({
                    closeBtn: 2,
                    icon: 0,
                    title: '删除数据库',
                    area: '400px', //宽高
                    btn: ['确定', '取消'],
                    content: '<div class="bt_conter bt-form" style="margin-top:-5px;margin-left:15px;">\
                            <div class="line">是否删除数据库【' + database + '】，确定要删除数据库吗?</div>\
                            <div class="line" style="padding:0;">\
                                <span class="tname" style="width:170px;color:red;padding-right: 10px;text-align:left;">同时删除数据库备份文件</span>\
                                <div class="info-r c4" style="margin-bottom:0;line-height:33px;height:33px;"><input  type="checkbox" name="del_bak" placeholder="请输入数据库名称">\
                            </div>\
                        </div>\
                    </div>',
                    yes: function (index, layero) {
                        var del_bak = $('[name="del_bak"]').prop('checked') ? 1 : 0;
                        layer.close(confirm);
                        _this.del_database_req({database: database, del_bak: del_bak}, function (res) {
                            _this.create_database_view(function () {
                                layer.msg(res.data, {icon: res.status ? 1 : 2});
                            });
                        });
                    }
                });
            });

            // 保存配置文件(OK)
            $('.save_config_file').click(function () {
                _this.save_config_file(_this.config_code.getValue(), function (res) {
                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                });
            });

            // 保存配置文件(OK)
            $('.save_config_user_file').click(function () {
                _this.save_user_config_file(_this.config_user_code.getValue(), function (res) {
                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                });
            });

            // 设置存储位置
            $('.btn_change_path').click(function () {
                var dir = $('#database_dir_val').val();
                if (dir == '') {
                    layer.msg('请输入数据库存储位置！', {icon: 2});
                    return false;
                }
                _this.set_database_dir({
                    data_directory: dir
                }, function (res) {
                    console.log(res.data);
                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                })
            });

            // 设置存储端口
            $('.btn_change_port').click(function () {
                var port = $('#database_port_val').val();
                if (port == '') {
                    layer.msg('请输入数据库端口！', {icon: 2});
                    return false;
                }
                _this.set_database_port({
                    port: port,
                    type: "port",
                    ps: "pgsql"
                }, function (res) {
                    console.log(res.data);
                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                });
                bt.firewall.add_accept_port("port", port, "pgsql")//放行端口
            });

            $('.select_list').on('click', '.select li', function () {
                var install = $(this).attr('data-install');
                var notInstall = $(this).attr('data-not-install');
                $(this).addClass('active').siblings().removeClass('active');
                $('.select_list .select_item').html($(this).html());
                $('.select_list .select').hide();
                if (install == 0) {
                    $('.install_pgsql').show().attr({'disabled': 'disabled', 'title': '切换版本，请切换版本，请先卸载当前版本，同时手动备份当前数据库文件'})
                    $('.uninstall_pgsql').hide();
                } else {
                    $('.install_pgsql').hide();
                    $('.uninstall_pgsql').show();
                }
                if (notInstall === "0") $('.install_pgsql').removeAttr('disabled title');
            });

            $('.select_list .select_item').click(function (e) {
                e.stopPropagation();
                if ($('.select_list .select').attr('style').indexOf('block') > -1) {
                    $('.select_list .select').hide();
                } else {
                    $('.select_list .select').show();
                }
                $(document).click(function (e) {
                    e.stopPropagation();
                    $('.select_list .select').hide();
                });
            });

            // 安装版本
            $('.install_pgsql').click(function () {
                var version_dow = $('.select_list .select .active').attr('data-downurl');
                var version_num = $('.select_list .select .active').attr('data-version');
                var confirm = layer.confirm('是否安装【' + version_num + '】数据库？', {title: '提示', btn: ['确定', '取消'], icon: 0, closeBtn: 2}, function () {
                    _this.total_version_req({pgsql_version: version_dow, tips: '正在安装PgSQL中，请稍后...'}, function (res) {
                        if (res.status) {
                            $('.install_version_box .install_log').css({'display': 'block'})
                            _this.inspect_version_install(version_num);
                        } else {
                            layer.msg(res.data, {icon: 2});
                        }
                    });
                });
            });

            // 卸载版本
            $('.uninstall_pgsql').click(function () {
                var version_dow = $('.select_list .select .active').attr('data-downurl');
                var version_num = $('.select_list .select .active').attr('data-version');
                var confirm = layer.open({
                    icon: 0,
                    closeBtn: 2,
                    title: '提示',
                    area: '400px', //宽高
                    btn: ['确定', '取消'],
                    content: '<div class="bt_conter bt-form" style="margin-top:-5px;margin-left:15px;">\
                            <div class="line">是否卸载数据库【' + version_num + '】，确定要卸载数据库吗?</div>\
                            <div class="line">\
                                <span class="tname" style="width:170px;color:red;padding-right: 10px;text-align:left;">同时删除数据库备份文件</span>\
                                <div class="info-r c4" style="margin-bottom:0;line-height:33px;height:33px;"><input  type="checkbox" name="del_bak" placeholder="请输入数据库名称">\
                            </div>\
                        </div>\
                    </div>',
                    yes: function (index, layero) {
                        var del_bak = $('[name="del_bak"]').prop('checked') ? 1 : 0;
                        layer.close(confirm);
                        _this.total_version_req({pgsql_unInstall: '1', del_bak: del_bak, tips: '正在卸载PgSQL中，请稍后...'}, function (res) {
                            _this.create_version_view(function () {
                                _this.pgsql_version = false;//未安装
                                layer.msg(res.data, {icon: res.status ? 1 : 2});
                            });
                        });
                    }
                })
            });

            // 保存PgSQL性能配置
            $('.save_pgsql_property').click(function () {
                var data = {};
                $('.database_property .bt-form .line input').each(function (index, element) {
                    data[$(this).attr('name')] = $(this).val() + ($(this).attr('unit') || '');
                })
                data['listen_addresses'] = $('[name="listen_addresses"]').val();
                _this.set_database_property({status_data: JSON.stringify(data)}, function (res) {
                    layer.msg(res.data, {icon: res.status ? 1 : 2});
                });
            });

            this.create_service_view();
        },

        // 创建状态视图
        create_service_view: function () {
            this.get_service_state(function (res) {
                var status = res.data[1] == 1 ? true : false;
                $('.service_view .status .glyphicon').removeClass(status ? 'glyphicon-pause' : 'glyphicon-play').addClass(status ? 'glyphicon-play' : 'glyphicon-pause').css('color', (status ? '#20a53a' : 'red'))
                $(!status ? '.btn_server_start' : '.btn_server_stop').show();
                $(status ? '.btn_server_start' : '.btn_server_stop').hide();
                $('.service_view .status span:eq(0)').html(res.data[0])
            })
        },

        // 获取状态请求
        get_service_state: function (callback) {
            this.send({
                tips: '正在获取服务状态，请稍后...',
                method: 'get_service',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 创建数据库列表视图
        create_database_view: function (callback) {
            var _html = '';
            this.get_database_list(function (res) {
                var rdata = res.data;
                for (var i = 0; i < rdata.length; i++) {
                    _html += '<tr data-database="' + rdata[i].database + '">\
                        <td>' + rdata[i].database + '</td>\
                        <td>' + rdata[i].username + '</td>\
                        <td>\
                            <span data-paw="' + rdata[i].password + '">******</span>\
                            <span class="glyphicon glyphicon-eye-open cursor set_paw_ico" style="margin-left:10px"></span>\
                            <span class="ico-copy cursor copy_paw" style="margin-left:10px" title="复制密码" data-clipboard-text="' + rdata[i].password + '" ></span>\
                        </td>\
                        <td>\
                            <a href="javascript:;" class="backups_list btlink" data-database="' + rdata[i].database + '">备份</a>&nbsp;&nbsp;|&nbsp;&nbsp;\
                            <a href="javascript:;" class="import_backups btlink" data-database="' + rdata[i].database + '">导入</a>\
                        </td>\
                        <td style="text-align:right;">\
                            <a href="javascript:;" class="btlink authority_manage" data-database="' + rdata[i].database + '" data-username="' + rdata[i].username + '" data-listenIp="' + rdata[i].listen_ip + '">权限</a>&nbsp;|&nbsp;\
                            <a href="javascript:;" class="btlink change_password"data-database="' + rdata[i].database + '" data-username="' + rdata[i].username + '" data-password="' + rdata[i].password + '">改密</a>&nbsp;|&nbsp;\
                            <a href="javascript:;" class="btlink del_database" data-database="' + rdata[i].database + '" >删除</a>\
                        </td>\
                    </tr>'
                }
                $('.database_table').html(_html);
                if (callback) callback();
            });
        },

        // 获取数据库列表
        get_database_list: function (callback) {
            this.send({
                tips: '正在获取数据库列表，请稍后...',
                method: 'get_database_list',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 设置数据库密码
        set_password_req: function (data, callback) {
            this.send({
                tips: '正在修改数据库密码，请稍后...',
                method: 'modify_pgsql_password',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 设置权限请求
        set_authority_req: function (data, callback) {
            this.send({
                tips: '正在设置数据库权限，请稍后...',
                method: 'modify_pgsql_listen_ip',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 删除数据库
        del_database_req: function (data, callback) {
            this.send({
                tips: '正在删除数据库，请稍后...',
                method: 'del_pgsql_db',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 添加数据库请求
        add_database_req: function (data, callback) {
            this.send({
                tips: '正在添加数据库，请稍后...',
                method: 'create_user',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建导入视图
        create_import_view: function (callback) {
            var _html = '';
            this.get_import_list(function (res) {
                var rdata = res.data;
                for (var i = 1; i < rdata.length; i++) {
                    _html += '<tr>\
                        <td>' + rdata[i].filename + '</td>\
                        <td>' + rdata[i].file_size + '</td>\
                        <td>' + rdata[i].create_time + '</td>\
                        <td style="text-align: right;">\
                            <a href="javascript:;" class="btlink import_backups" data-filepath="' + rdata[i].file_path + '" data-filename="' + rdata[i].filename + '">恢复</a>&nbsp;|&nbsp;\
                            <a href="javascript:;" class="btlink del_backups" data-filename="' + rdata[i].filename + '">删除</a>\
                        </td>\
                    </tr>'
                }
                $('.import_file_table').html(_html);
                if (callback) callback();
            });
        },

        // 获取导入列表
        get_import_list: function (callback) {
            this.send({
                tips: '正在获取数据库导入列表，请稍后...',
                method: 'get_import_bak_list',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 上传导入文件请求
        upload_files: function () {
            var path = "/www/backup/pgsql_bak/upload", _this = this;
            var index = layer.open({
                type: 1,
                closeBtn: 2,
                title: '上传数据库备份文件 --- <span style="color:red;">' + lan.database.input_up_type + '</span>',
                area: ['500px', '500px'],
                shadeClose: false,
                content: '<div class="fileUploadDiv"><input type="hidden" id="input-val" value="' + path + '" />\
                            <input type="file" id="file_input"  multiple="true" autocomplete="off" />\
                            <button type="button"  id="opt" autocomplete="off">' + lan.files.up_add + '</button>\
                            <button type="button" id="up" autocomplete="off" >' + lan.files.up_start + '</button>\
                            <span id="totalProgress" style="position: absolute;top: 7px;right: 147px;"></span>\
                            <span style="float:right;margin-top: 9px;">\
                            <font>' + lan.files.up_coding + ':</font>\
                            <select id="fileCodeing" >\
                                <option value="byte">' + lan.files.up_bin + '</option>\
                            </select>\
                            </span>\
                            <button type="button" id="filesClose" autocomplete="off">' + lan.public.close + '</button>\
                            <ul id="up_box"></ul></div>',

            });
            $("#filesClose").click(function () {
                layer.close(index);
                _this.create_import_view();
            });
            UploadStart(true);
        },

        // 恢复导入请求
        recover_import_req: function (data, callback) {
            this.send({
                tips: '正在导入数据库备份，请稍后...',
                data: data,
                method: 'pgsql_back_import',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 删除导入请求
        del_import_req: function (data, callback) {
            this.send({
                method: 'del_import_pgsql_bak',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 创建数据库备份列表
        create_backups_list: function (data, callback) {
            var _html = '', rdata = '';
            this.get_backups_list(data, function (res) {
                rdata = res.data;
                for (var i = 0; i < rdata.length; i++) {
                    _html += '<tr>\
                        <td>' + rdata[i].filename + '</td>\
                        <td>' + rdata[i].file_size + '</td>\
                        <td>' + rdata[i].create_time + '</td>\
                        <td style="text-align: right;">\
                            <a href="javascript:;" class="btlink import_backups" data-filename="' + rdata[i].filename + '">恢复</a>&nbsp;|&nbsp;\
                            <a href="/download?filename=' + rdata[i].file_path + '&name=' + rdata[i].filename + '" class="btlink download_backups" data-filename="' + rdata[i].filename + '">下载</a>&nbsp;|&nbsp;\
                            <a href="javascript:;" class="btlink del_backups" data-filename="' + rdata[i].filename + '">删除</a>\
                        </td>\
                    </tr>'
                }
                $('.backups_table').html(_html);
                if (callback) callback();
            });
        },

        // 获取指定数据库备份列表
        get_backups_list: function (data, callback) {
            this.send({
                tips: '正在获取数据库备份列表，请稍后...',
                data: data,
                method: 'get_pgsql_bak_list',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 添加备份请求
        add_backups_req: function (data, callback) {
            this.send({
                tips: '正在添加数据库备份，请稍后...',
                data: data,
                method: 'pgsql_back',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 恢复备份请求
        recover_backups_req: function (data, callback) {
            this.send({
                tips: '正在导入数据库备份，请稍后...',
                data: data,
                method: 'pgsql_restore',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 删除备份请求
        del_backups_req: function (data, callback) {
            this.send({
                tips: '正在删除数据库备份，请稍后...',
                data: data,
                method: 'del_pgsql_bak',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 获取pgsql安装状态
        get_pgsql_install_status: function (callback) {
            this.send({
                load: 3,
                data: {get_pgsql_install_log: "1"},
                method: 'Install_uninstall',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 创建版本视图
        create_version_view: function (callback) {
            var _html = '', _item = '';
            this.total_version_req({get_pgsql_version: 1, get_pgsql_install_info: 1, tips: '获取PgSQL版本中，请稍后...'}, function (res) {
                var version_list = res.data.pgsql_install_info;
                var version_pgsql = res.data.pgsql_version;
                var version_num = parseFloat(version_pgsql.replace(/^psql\s\(PostgreSQL\)\s([0-9\.]+)\n/, '$1'));
                if (version_pgsql == '') {
                    $('.install_pgsql').show().next().hide();
                } else {
                    $('.install_pgsql').hide().next().show();
                }
                for (var i = 0; i < version_list.length; i++) {
                    var active = version_list[i].pgsql_version.indexOf(version_num) > -1 ? true : false;
                    if (active) _item = version_list[i].pgsql_version;
                    _html += '<li data-install="' + (active ? 1 : 0) + '" data-not-install="' + (version_pgsql == '' ? 0 : 1) + '" data-version="' + version_list[i].pgsql_version + '" data-downUrl="' + version_list[i].down_url + '" ' + (active ? 'class="active"' : '') + ' ' + (version_pgsql == '' && i == 0 ? 'class="active"' : '') + '>' + version_list[i].pgsql_version + (active ? '<i style="font-style: normal;color: #20a53a;">&nbsp;&nbsp;[ 已安装 ]&nbsp;&nbsp;</i>' : '') + '</li>';
                }
                $('.install_pgsql').removeAttr('disabled');
                $('.install_version_box .select').html(_html);
                $('.install_version_box .select_item').html((_item == '' ? version_list[0].pgsql_version : _item) + (version_pgsql != '' ? '<i style="font-style: normal;color: #20a53a;">&nbsp;&nbsp;[ 已安装 ]&nbsp;&nbsp;</i>' : ''));
                if (callback) callback();
            });
        },

        // 检查版本更新
        inspect_version_install: function (version) {
            var _this = this;
            var timeout = setInterval(function () {
                _this.get_pgsql_install_status(function (res) {
                    if (res.status) $('.install_version_box .install_log').val($('.install_version_box .install_log').val() + res.data);
                    var ele = document.getElementsByClassName('install_log')[0];
                    ele.scrollTop = ele.scrollHeight;
                    $('.select_list .select_item').unbind();
                    $('.install_pgsql').html('正在安装').attr({'disabled': 'disabled'});
                    if (res.data.indexOf("SUCCESS") > -1) {
                        clearTimeout(timeout);
                        _this.send({
                            url: '/firewall?action=AddAcceptPort',
                            data: {port: 5432, type: "port", ps: "PgSQL数据库端口放行"},
                            check: true,
                            success: function (res) {
                                layer.msg(res.msg, {icon: res.status ? 1 : 2});
                                _this.create_version_view(function (res) {
                                    _this.pgsql_version = true;//已安装
                                    $('.install_pgsql').html('安装版本').removeAttr('disabled');
                                    $('.install_version_box .install_log').css({'display': 'none'});
                                    $('.tomcat_log').val('');
                                    $('.select_list .select_item').click(function (e) {
                                        e.stopPropagation();
                                        if ($('.select_list .select').attr('style').indexOf('block') > -1) {
                                            $('.select_list .select').hide();
                                        } else {
                                            $('.select_list .select').show();
                                        }
                                        $(document).click(function (e) {
                                            e.stopPropagation();
                                            $('.select_list .select').hide();
                                        });
                                    });
                                    layer.msg('PgSQL数据库【' + version + '】安装成功', {icon: 1});
                                });
                            }
                        });
                    }
                });
            }, 2000);
        },

        // 全部版本请求
        total_version_req: function (data, callback) {
            this.send({
                tips: data.tips,
                data: data,
                method: 'Install_uninstall',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 创建用户安全配置视图
        create_user_config_view: function () {
            var _this = this;
            this.get_user_config_file(function (res) {
                $('#config_user_file').val(res.data);
                $('.config_user_file .CodeMirror').remove();
                _this.config_user_code = CodeMirror.fromTextArea(document.getElementById("config_user_file"), {
                    extraKeys: {
                        "Ctrl-F": "findPersistent",
                        "Ctrl-H": "replaceAll",
                        "Ctrl-S": function (res) {
                            _this.save_user_config_file(res.getValue(), function (res) {
                                layer.msg(res.data, {icon: res.status ? 1 : 2});
                            });
                        }
                    },
                    mode: "text/x-nginx-conf",
                    lineNumbers: true,
                    matchBrackets: true,
                    matchtags: true,
                    autoMatchParens: true
                });
            });
        },

        // 获取用户安全配置文件
        get_user_config_file: function (callback) {
            this.send({
                tips: '正在获取客户端认证配置文件信息，请稍后...',
                method: 'get_clint_config',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 保存用户安全配置文件
        save_user_config_file: function (data, callback) {
            this.send({
                tips: '正在保存配置文件信息，请稍后...',
                data: {text_conf: data},
                method: 'save_get_clint_conf',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建配置视图
        create_config_view: function () {
            var _this = this;
            this.get_config_file(function (res) {
                $('#config_file').val(res.data);
                $('.config_file .CodeMirror').remove();
                _this.config_code = CodeMirror.fromTextArea(document.getElementById("config_file"), {
                    extraKeys: {
                        "Ctrl-F": "findPersistent",
                        "Ctrl-H": "replaceAll",
                        "Ctrl-S": function (res) {
                            _this.save_config_file(res.getValue(), function (res) {
                                layer.msg(res.data, {icon: res.status ? 1 : 2});
                            });
                        }
                    },
                    mode: "text/x-nginx-conf",
                    lineNumbers: true,
                    matchBrackets: true,
                    matchtags: true,
                    autoMatchParens: true
                });
            });
        },

        // 获取配置文件
        get_config_file: function (callback) {
            this.send({
                tips: '正在获取配置文件信息，请稍后...',
                method: 'get_config',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 保存配置文件
        save_config_file: function (data, callback) {
            this.send({
                tips: '正在保存配置文件信息，请稍后...',
                data: {text_conf: data},
                method: 'save_conf',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建数据库目录存储位置视图
        create_dir_view: function () {
            this.get_database_dir(function (res) {
                $('#database_dir_val').val(res.data)
            });
        },

        // 获取数据库存储位置
        get_database_dir: function (callback) {
            this.send({
                tips: '正在获取数据库存储目录，请稍后...',
                method: 'get_data_directory',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 设置数据库存储目录
        set_database_dir: function (data, callback) {
            this.send({
                tips: '正在设置数据库存储目录，请稍后...',
                data: data,
                method: 'modify_data_directory',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 创建数据库目录存储位置视图
        create_port_view: function () {
            this.get_database_port(function (res) {
                $('#database_port_val').val(res.data)
            });
        },

        // 获取数据库存储位置
        get_database_port: function (callback) {
            this.send({
                tips: '正在获取数据库端口，请稍后...',
                method: 'get_port',
                success: function (res) {
                    if (callback) callback(res);
                }
            })
        },

        // 设置数据库存储目录
        set_database_port: function (data, callback) {
            this.send({
                tips: '正在设置数据库端口，请稍后...',
                data: data,
                method: 'save_port',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建状态视图
        create_status_view: function () {
            this.get_database_status(function (res) {
                var rdata = res.data, _html = '';
                for (var i in rdata) {
                    _html += '<tr>\
                        <td><span style="font-weight: 600;">' + i + '</span></td>\
                        <td style="width:150px">' + rdata[i] + '</td>\
                    </tr>';
                }
                $('#tab-pgsql-status tbody').html(_html);
            });
        },

        // 获取数据库状态
        get_database_status: function (callback) {
            this.send({
                tips: '正在获取数据库状态，请稍后...',
                method: 'get_pgsql_current_status',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建数据库性能配置视图
        create_property_view: function (callback) {
            var _this = this, _html = '';
            _this.get_database_property(function (res) {
                for (var i in res) {
                    if (i != 'status') {
                        if (i == 'listen_addresses') {
                            _html += '<div class="line">\
                                <span class="tname">listen_addresses</span>\
                                <div class="info-r">\
                                    <select name="listen_addresses" class="bt-input-text mr5 key_buffer_size">\
                                        <option value="*" ' + (res[i][0] == '*' ? 'selected="selected"' : '') + '>所有人</option>\
                                        <option value="localhost" ' + (res[i][0] == 'localhost' ? 'selected="selected"' : '') + '>本机</option>\
                                    </select>\
                                </div>\
                            </div>'
                        } else {
                            _html += '<div class="line">\
                                <span class="tname">' + i + '</span>\
                                <div class="info-r">\
                                    <input name="' + i + '" class="bt-input-text mr5 key_buffer_size" type="number" style="width:70px" unit="' + res[i][1] + '" value="' + res[i][0] + '">\
                                    <span class="c9 mt10 mr5"><font>' + (res[i][1] != "" ? ('，' + res[i][1] + '，') : '，') + res[i][2] + '</font></span>\
                                </div>\
                            </div>'
                        }
                    }
                }
                $('.database_property .bt-form').html(_html);
            });
        },

        // 获取数据库性能配置
        get_database_property: function (callback) {
            this.send({
                tips: '正在获取数据库性能配置,请稍后...',
                method: 'get_pgsql_status',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 设置数据库性能配置
        set_database_property: function (data, callback) {
            this.send({
                tips: '正在保存数据库性能数据,请稍后...',
                method: 'save_pgsql_status',
                data: data,
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建数据库日志视图
        create_logs_view: function () {
            this.get_database_logs(function (res) {
                $('#database_logs_val').val(res.data);
                setTimeout(function () {
                    var scrollDom = document.getElementById('database_logs_val');
                    scrollDom.scrollTop = scrollDom.scrollHeight;
                }, 200);
            });
        },

        // 获取数据库日志
        get_database_logs: function (callback) {
            this.send({
                tips: '正在获取数据库日志,请稍后...',
                method: 'get_pgsql_log',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 创建数据库慢日志视图
        create_slow_logs_view: function () {
            this.get_slow_logs(function (res) {
                $('#database_slow_logs_val').val(res.data);
                setTimeout(function () {
                    var scrollDom = document.getElementById('database_slow_logs_val');
                    scrollDom.scrollTop = scrollDom.scrollHeight;
                }, 200);
            });
        },

        // 获取数据库慢日志
        get_slow_logs: function (callback) {
            this.send({
                tips: '正在获取数据库慢日志,请稍后...',
                method: 'get_slow_pgsql_log',
                success: function (res) {
                    if (callback) callback(res);
                }
            });
        },

        // 请求封装
        send: function (obj) {
            var loadT = '';
            if (obj.load == undefined) obj.load = 0;
            if (obj.url == undefined) {
                if (obj.plugin_name === undefined && this.plugin_name !== undefined) obj.plugin_name = this.plugin_name
                if (!obj.plugin_name || !obj.method) {
                    layer.msg('插件类名称，或插件方法名称缺失!', {icon: 2});
                    return false;
                }
            }
            if (obj.load === 0) {
                loadT = layer.msg(obj.tips, {
                    icon: 16,
                    time: 0,
                    shade: 0.3
                });
            } else if (obj.load === 1 || (obj.tips == undefined && obj.load == undefined)) {
                loadT = layer.load();
            }
            $.ajax({
                type: 'POST',
                url: obj.url != undefined ? obj.url : ('/plugin?action=a&name=' + obj.plugin_name + '&s=' + obj.method),
                data: obj.data || {},
                timeout: obj.timeout || 99999999,
                complete: function (res) {
                    if (obj.load === 0 || obj.load === 1) layer.close(loadT);
                },
                success: function (rdata) {
                    if (obj.check) {
                        obj.success(rdata);
                        return
                    }
                    if (rdata.status === false) {
                        layer.msg(rdata.data, {icon: 2});
                        return
                    }
                    obj.success(rdata);
                },
                error: function (ex) {
                    if (!obj.error) {
                        obj.msg || obj.msg == undefined ? layer.msg('请求过程发现错误!', {icon: 2}) : '';
                        return;
                    }
                    return obj.error(ex);
                }
            });
        }
    }
    pgsql.init();
</script>